package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.req.personne.PersonneControlReqVo;
import com.ruoyi.system.domain.vo.req.personne.PersonneEditReqVo;
import com.ruoyi.system.domain.vo.req.personne.PersonneQueryReqVo;
import com.ruoyi.system.domain.vo.resp.personne.PersonneCountRespVo;
import com.ruoyi.system.domain.vo.resp.personne.PersonneListRespVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.DataScreeningPersonnel;
import com.ruoyi.system.service.IDataScreeningPersonnelService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 被排查人员Controller
 * 
 * @author ruoyi
 * @date 2024-06-25
 */
@Slf4j
@RestController
@RequestMapping("/personnel")
@RequiredArgsConstructor
@Api( tags = "被排查人员相关接口")
public class DataScreeningPersonnelController extends BaseController
{

    private final IDataScreeningPersonnelService dataScreeningPersonnelService;

    /**
     * 查询被排查人员列表
     */
    @ApiOperation(value = "查询被排查人员列表")
    //@RequiresPermissions("system:personnel:list")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody PersonneQueryReqVo reqVo)
    {
//        startPage();
        log.info("查询被排查人员列表，param：{}", reqVo);
        List<PersonneListRespVo> list = dataScreeningPersonnelService.selectPersonneList(reqVo);
        return getDataTable(list);
    }

    /**
     * 导出被排查人员列表
     */
    //@RequiresPermissions("system:personnel:export")
    @Log(title = "被排查人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataScreeningPersonnel dataScreeningPersonnel)
    {
        List<DataScreeningPersonnel> list = dataScreeningPersonnelService.selectDataScreeningPersonnelList(dataScreeningPersonnel);
        ExcelUtil<DataScreeningPersonnel> util = new ExcelUtil<DataScreeningPersonnel>(DataScreeningPersonnel.class);
        util.exportExcel(response, list, "被排查人员数据");
    }

    /**
     * 获取被排查人员详细信息
     */
    @ApiOperation(value = "获取被排查人员详细信息")
    //@RequiresPermissions("system:personnel:query")
    @GetMapping(value = "/getInfo")
    public AjaxResult getInfo(@RequestParam("screeningPersonnelId") Long screeningPersonnelId)
    {
        log.info("获取被排查人员详细信息，param：{}", screeningPersonnelId);
        return AjaxResult.success(dataScreeningPersonnelService.selectPersonneListById(screeningPersonnelId));
    }

    /**
     * 人员管控看板
     */
    @ApiOperation(value = "人员管控看板")
    //@RequiresPermissions("system:personnel:query")
    @GetMapping(value = "/selectPersonneCountList")
    public PersonneCountRespVo selectPersonneCountList()
    {
        return dataScreeningPersonnelService.selectPersonneCountList();
    }

    /**
     * 新增被排查人员
     */
    //@RequiresPermissions("system:personnel:add")
    @Log(title = "被排查人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataScreeningPersonnel dataScreeningPersonnel)
    {
        return toAjax(dataScreeningPersonnelService.insertDataScreeningPersonnel(dataScreeningPersonnel));
    }

    /**
     * 修改被排查人员
     */
    @ApiOperation(value = "修改被排查人员")
    //@RequiresPermissions("system:personnel:edit")
    @Log(title = "被排查人员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody PersonneEditReqVo reqVo)
    {
        log.info("修改被排查人员，param：{}", reqVo);
        return toAjax(dataScreeningPersonnelService.updateDataScreeningPersonnel(reqVo));
    }

    /**
     * 人员管控
     */
    @ApiOperation(value = "人员管控")
    //@RequiresPermissions("system:personnel:edit")
    @Log(title = "被排查人员", businessType = BusinessType.UPDATE)
    @PostMapping("/control")
    public AjaxResult control(@RequestBody PersonneControlReqVo reqVo)
    {
        log.info("人员管控，param：{}", reqVo);
        return toAjax(dataScreeningPersonnelService.control(reqVo));
    }

    /**
     * 删除被排查人员
     */
    //@RequiresPermissions("system:personnel:remove")
    @Log(title = "被排查人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{screeningPersonnelIds}")
    public AjaxResult remove(@PathVariable Long[] screeningPersonnelIds)
    {
        return toAjax(dataScreeningPersonnelService.deleteDataScreeningPersonnelByScreeningPersonnelIds(screeningPersonnelIds));
    }
}
